package com.chengxiaoxiao.utils;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.servlet.http.HttpServletResponse;

/**
 * JSON的工具类
 */
public class JSONUtils {

    public static void toJson(HttpServletResponse response, Object map) {

        if (map == null) {
            throw new IllegalArgumentException("JSONUtils未传入任何参数");
        }
        try {
            String json = JSONObject.fromObject(map).toString();
            response.getWriter().println(json);
        } catch (Exception e) {

        }

    }

    public static void toJsonArray(HttpServletResponse response, Object list) {
        if (list == null) {
            throw new IllegalArgumentException("JSONUtils未传入任何参数");
        }
        try {
            String json = JSONArray.fromObject(list).toString();
            response.getWriter().println(json);

        } catch (Exception e) {
        }
    }
}
